package com.Lyf.user.elasticsearch.index;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.util.Date;

/**
 * 创建Elasticsearch索引和映射
 */


/**
 * Document 指定索引的名称
 */
@Document(indexName = "book")
//创建索引的同时指定分片数和每个分片的备份数
@Setting(shards = 5, replicas = 1)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Book {


    @Id
    private String id;
    /**
     * type 字段类型
     * analyzer:所使用的分词器名称
     * index 该字段是否参与检索
     * store 是否使用额外空间存储该字段
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word",index =true,store = false)
    private String name;

    @Field(type = FieldType.Keyword)
    private String author;

    @Field(type = FieldType.Long)
    private Long count;

    @Field(type = FieldType.Date,format = DateFormat.date)
    private Date on_sale;

    @Field(type = FieldType.Text,analyzer = "ik_max_word" )
    private String descr;
}
